﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace OwElectrePromethee
{
    public class ElectreTri : IOwMethod
    {
        public string Perform(bool fromFile = true)
        {
            List<EKryterium> kryteria = LoadKryteria();
            List<EWariant> warianty = LoadWarianty();
            List<EWariant> profile = LoadProfile();
            CheckKryteria(kryteria, warianty, profile);

            double progOdciecia = 0.55d;


            //test zgodności
            EPrzewyższanie[,] compliance = new EPrzewyższanie[warianty.Count, profile.Count];

            using (TextWriter writer = new StreamWriter("output.txt"))
            {
                foreach (var wariant in warianty)
                {
                    writer.WriteLine("wariant {0}", wariant.ToString());
                    foreach (var profil in profile)
                    {
                        writer.WriteLine(" profil {0}", profil.ToString());

                        var comparisionList = new List<Tuple<int, double>>();

                        //ok, mam konkretny wariant i profil, porównuję je
                        foreach (var kryterium in kryteria)// porównuję każdy wariant ze wszystkimi profilami, na każdym kryterium
                        {

                            var wariantKryteriumValue = wariant.K.First(k => k.Id == kryterium.Id).Value;
                            var profilKryteriumValue = profil.K.First(k => k.Id == kryterium.Id).Value;

                            var relacja = kryterium.Compare(wariantKryteriumValue, profilKryteriumValue);

                            if (relacja != ERelacje.Nieporownywalne)//wyliczam cząstkowy wsp. zgodności
                            {
                                var ci = kryterium.getCi(wariantKryteriumValue, profilKryteriumValue);
                                comparisionList.Add(new Tuple<int, double>(kryterium.Id, ci));
                                writer.WriteLine("  kryterium {0}, Rel: {1}, Ci: {2}", kryterium, relacja, ci);

                            }
                            else writer.WriteLine("  kryterium {0}, Rel: {1}", kryterium, relacja);
                        }

                        if (!comparisionList.Any()) compliance[wariant.Id - 1, profil.Id - 1] = EPrzewyższanie._1;
                        else
                        {
                            var CiWeighted = comparisionList.Select(Ci => Ci.Item2 * kryteria.First(k => k.Id == Ci.Item1).Waga).ToList();
                            var Weights = comparisionList.Select(Ci => kryteria.First(k => k.Id == Ci.Item1).Waga).ToList();

                            double cGlobal = CiWeighted.Sum() / Weights.Sum();
                            writer.WriteLine("\tWsp. zgodności: {0}", cGlobal);

                            if (cGlobal >= progOdciecia) //Test niezgodności
                            {
                                bool veto = false;
                                foreach (var kryterium in kryteria)
                                {
                                    var wariantKryteriumValue = wariant.K.First(k => k.Id == kryterium.Id).Value;
                                    var profilKryteriumValue = profil.K.First(k => k.Id == kryterium.Id).Value;
                                    var relacja = kryterium.Compare(wariantKryteriumValue, profilKryteriumValue);

                                    if (relacja != ERelacje.Nieporownywalne)
                                    {
                                        if (kryterium.Typ == EKryteriumTyp.Zysk)
                                        {
                                            using (TextWriter writer2 = new StreamWriter("niezgodnosc.txt", true))
                                            {
                                                if (profilKryteriumValue - wariantKryteriumValue >= kryterium.V)
                                                    veto = true;
                                                writer2.WriteLine("Wariant:{0} Profil:{1} Kryt:{2} veto = vetoCalc:{3} >= {4} ({5})",
                                                    wariant.Id, profil.Id, kryterium.Id, profilKryteriumValue - wariantKryteriumValue,
                                                    kryterium.V, profilKryteriumValue - wariantKryteriumValue >= kryterium.V);
                                            }
                                        }
                                        else if (kryterium.Typ == EKryteriumTyp.Koszt)
                                        {
                                            using (TextWriter writer2 = new StreamWriter("niezgodnosc.txt", true))
                                            {
                                                if (profilKryteriumValue - wariantKryteriumValue <= kryterium.V)
                                                    veto = true;
                                                writer2.WriteLine("Wariant:{0} Profil:{1} Kryt:{2} veto = vetoCalc:{3} <= {4} ({5})",
                                                    wariant.Id, profil.Id, kryterium.Id, profilKryteriumValue - wariantKryteriumValue,
                                                    kryterium.V, profilKryteriumValue - wariantKryteriumValue <= kryterium.V);
                                            }
                                        }
                                    }
                                }
                                if (!veto) compliance[wariant.Id - 1, profil.Id - 1] = EPrzewyższanie.SS;
                                else compliance[wariant.Id - 1, profil.Id - 1] = EPrzewyższanie.SS; //TODO: tu powinno być weto, ale nie znam zasady działania veta
                            }
                            else compliance[wariant.Id - 1, profil.Id - 1] = EPrzewyższanie._S;
                        }
                    }
                    writer.WriteLine();
                }
            }
            //TODO: OK, już porównałem sobie, pozostaje dobrać klasy dla wariantów :)))
            Console.WriteLine(EPorównanieHelper.WypiszKlasy(compliance));
            //EPorównanieHelper.Rysuj(compliance);


            return null;
        }



        #region helpers
        public static List<EWariant> LoadWarianty()
        {
            var dialog = new OpenFileDialog();
            dialog.Title = "Wczytywanie Wariantów";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                using (TextReader rstream = new StreamReader(dialog.FileName))
                {
                    var serializer = new XmlSerializer(typeof(EWariantyList));
                    var wariantyList = (EWariantyList)serializer.Deserialize(rstream);
                    if (wariantyList != null) return wariantyList.List;
                    else throw new ArgumentException("Lista wariantów jest pusta.");
                }
            }
            else throw new FileNotFoundException("Podaj poprawny plik Wariantów.");
        }

        public static List<EWariant> LoadProfile()
        {
            var dialog = new OpenFileDialog();
            dialog.Title = "Wczytywanie Profili";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                using (TextReader rstream = new StreamReader(dialog.FileName))
                {
                    var serializer = new XmlSerializer(typeof(EWariantyList));
                    var profileList = (EWariantyList)serializer.Deserialize(rstream);
                    if (profileList != null) return profileList.List;
                    else throw new ArgumentException("Lista profili jest pusta.");
                }
            }
            else throw new FileNotFoundException("Podaj poprawny plik Profili.");
        }

        public static List<EKryterium> LoadKryteria()
        {
            var dialog = new OpenFileDialog();
            dialog.Title = "Wczytywanie Kryteriów";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                using (TextReader rstream = new StreamReader(dialog.FileName))
                {
                    var serializer = new XmlSerializer(typeof(EKryteriaList));
                    var kryteriaList = (EKryteriaList)serializer.Deserialize(rstream);
                    if (kryteriaList != null) return kryteriaList.List;
                    else throw new ArgumentException("Lista kryteriów jest pusta.");
                }
            }
            else throw new FileNotFoundException("Podaj poprawny plik kryteriów.");
        }

        public static void CheckKryteria(List<EKryterium> kryteria, List<EWariant> warianty, List<EWariant> profile)
        {
            //TODO: Sprawdzanie czy każdy wariant/profil ma kryterium o id z listy kryteriów
            if (!warianty.All(w => w.K.Count == kryteria.Count))
                throw new FileLoadException("Plik wariantów zawiera inną liczbę kryteriów niż plik kryteriów.");
            if (!profile.All(p => p.K.Count == kryteria.Count))
                throw new FileLoadException("Plik profili zawiera inną liczbę kryteriów niż plik kryteriów.");
        }

        public static void CheckKryteria(List<EKryterium> kryteria, List<EWariant> warianty)
        {
            //TODO: Sprawdzanie czy każdy wariant/profil ma kryterium o id z listy kryteriów
            if (!warianty.All(w => w.K.Count == kryteria.Count))
                throw new FileLoadException("Plik wariantów zawiera inną liczbę kryteriów niż plik kryteriów.");
        }
        #endregion

        #region generowanie_danych
        public static void GenerateElectreTriData()
        {
            #region generowanie_danych
            GenerateKryteria();
            GenerateWarianty();
            GenerateProfile();


            var ciOutputToClean = new StreamWriter("getCi.txt", false);//czyszczę plik debug
            ciOutputToClean.Dispose();

            var vetoOutputToClean = new StreamWriter("niezgodnosc.txt", false);//czyszczę plik debug
            vetoOutputToClean.Dispose();
            #endregion
        }

        public static void GenerateElectreTriDataTest()
        {
            GenerateWariantyTestowe();
            GenerateKryteriaTestowe();
            GenerateProfileTestowe();
        }

        private static void GenerateWarianty()
        {
            var serializer = new XmlSerializer(typeof(EWariantyList));
            using (TextWriter wstream =
                new StreamWriter(
                    "warianty.txt"))
            {
                var warianty = new EWariantyList();

                warianty.List.Add(new EWariant(1, "W1", 810000, 1.56, 88, 6, 94, 3, 92, 7, 48, 5, 88, 4, 84, 1, 1338000, 1.73, 77, 6, 48, 3, 76, 6, 64));
                warianty.List.Add(new EWariant(2, "W2", 360000, 0.73, 64, 3, 68, 1, 40, 7, 47, 3, 32, 1, 49, 1, 480000, 1.06, 26, 3, 71, 1, 78, 1, 75));
                warianty.List.Add(new EWariant(3, "W3", 556000, 1.9, 61, 4, 71, 2, 90, 4, 55, 3, 49, 4, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                warianty.List.Add(new EWariant(4, "W4", 726000, 1.73, 68, 6, 87, 1, 91, 9, 56, 6, 49, 4, 92, 1, 1422000, 1.73, 52, 6, 92, 1, 92, 5, 75));
                warianty.List.Add(new EWariant(5, "W5", 690000, 0.6, 49, 5, 51, 2, 65, 10, 41, 4, 55, 5, 91, 1, 1135000, 0.6, 89, 5, 78, 2, 78, 2, 79));
                warianty.List.Add(new EWariant(6, "W6", 1280000, 0.775, 84, 8, 92, 8, 74, 8, 72, 7, 69, 7, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                warianty.List.Add(new EWariant(7, "W7", 1561000, 1.4, 86, 7, 83, 1, 70, 8, 97, 6, 81, 6, 56, 1, 1701000, 1.4, 94, 7, 77, 1, 64, 6, 61));
                warianty.List.Add(new EWariant(8, "W8", 1141000, 0.82, 79, 7, 68, 3, 64, 9, 85, 6, 90, 6, 81, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                warianty.List.Add(new EWariant(9, "W9", 660000, 1.06, 58, 3, 73, 1, 62, 10, 64, 2, 77, 2, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                warianty.List.Add(new EWariant(10, "W10", 702000, 3.73, 58, 3, 45, 1, 60, 6, 56, 2, 87, 2, 92, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));

                //warianty.List.Add(new EWariant(11, "W11", 873000, 2.73, 89, 3, 92, 1, 39, 5, 43, 2, 72, 2, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(12, "W12", 507000, 2.73, 71, 3, 89, 2, 72, 5, 55, 3, 86, 3, 73, 1, 465000, 2.4, 70, 3, 86, 2, 49, 3, 73));
                //warianty.List.Add(new EWariant(13, "W13", 1855000, 1.82, 75, 7, 78, 1, 84, 9, 71, 6, 76, 7, 70, 1, 1176000, 1.82, 79, 7, 89, 1, 91, 7, 85));
                //warianty.List.Add(new EWariant(14, "W14", 1188000, 1.06, 92, 9, 93, 1, 97, 10, 84, 8, 83, 9, 76, 1, 1125000, 1.06, 93, 9, 99, 1, 89, 7, 88));
                //warianty.List.Add(new EWariant(15, "W15", 1020000, 2.65, 74, 4, 87, 1, 51, 7, 62, 3, 57, 4, 60, 1, 656000, 2.4, 68, 4, 32, 1, 59, 2, 74));
                //warianty.List.Add(new EWariant(16, "W16", 360000, 1.4, 96, 3, 25, 3, 45, 7, 81, 3, 76, 3, 70, 1, 372000, 0.73, 72, 3, 36, 3, 84, 3, 85));
                //warianty.List.Add(new EWariant(17, "W17", 774000, 3.73, 61, 3, 27, 2, 64, 9, 51, 2, 56, 3, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(18, "W18", 588000, 3.06, 51, 3, 92, 2, 58, 7, 60, 2, 25, 3, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(19, "W19", 477000, 2.4, 90, 3, 46, 3, 63, 8, 36, 2, 32, 1, 69, 1, 573000, 3.4, 25, 3, 82, 3, 66, 2, 53));
                //warianty.List.Add(new EWariant(20, "W20", 804000, 3.4, 72, 3, 97, 2, 44, 10, 49, 2, 47, 3, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));

                //warianty.List.Add(new EWariant(21, 1196000, 2.9, 76, 4, 100, 4, 95, 4, 81, 4, 82, 4, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(22, 825000, 2.4, 90, 3, 46, 1, 88, 9, 96, 2, 28, 1, 99, 1, 552000, 2.73, 82, 3, 84, 1, 25, 2, 45));
                //warianty.List.Add(new EWariant(23, 771000, 2.4, 35, 3, 78, 1, 34, 7, 55, 2, 96, 1, 57, 1, 558000, 3.4, 95, 3, 98, 1, 80, 3, 39));
                //warianty.List.Add(new EWariant(24, 732000, 3.73, 45, 3, 93, 2, 36, 5, 46, 3, 34, 1, 44, 1, 789000, 3.73, 71, 3, 85, 2, 92, 3, 59));
                //warianty.List.Add(new EWariant(25, 432000, 3.4, 51, 3, 68, 2, 27, 10, 43, 3, 88, 1, 56, 1, 900000, 3.73, 85, 3, 37, 2, 62, 2, 96));
                //warianty.List.Add(new EWariant(26, 1266000, 1.23, 94, 6, 75, 5, 94, 9, 90, 5, 69, 6, 76, 1, 1176000, 1.4, 74, 6, 76, 5, 97, 4, 100));
                //warianty.List.Add(new EWariant(27, 789000, 0.73, 28, 3, 64, 3, 73, 6, 60, 2, 39, 2, 93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(28, 1144000, 2.9, 76, 4, 45, 3, 80, 4, 36, 3, 97, 2, 77, 1, 856000, 2.65, 39, 4, 78, 3, 47, 2, 72));
                //warianty.List.Add(new EWariant(29, 875000, 1.54, 77, 7, 86, 4, 63, 9, 63, 7, 97, 6, 69, 1, 1932000, 1.68, 83, 7, 92, 4, 75, 5, 67));
                //warianty.List.Add(new EWariant(30, 1768000, 1.52, 79, 8, 66, 7, 80, 9, 95, 7, 65, 6, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));

                //warianty.List.Add(new EWariant(31, 1848000, 0.82, 74, 7, 60, 4, 86, 8, 67, 7, 95, 6, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(32, 456000, 2.65, 58, 4, 86, 3, 43, 5, 94, 4, 44, 2, 91, 1, 524000, 0.65, 49, 4, 62, 3, 47, 3, 41));
                //warianty.List.Add(new EWariant(33, 846000, 1.73, 24, 3, 73, 2, 58, 8, 53, 3, 51, 3, 27, 1, 708000, 3.4, 55, 3, 61, 2, 41, 3, 55));
                //warianty.List.Add(new EWariant(34, 705000, 2.06, 42, 3, 67, 2, 30, 10, 65, 3, 100, 1, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(35, 735000, 1.06, 78, 3, 56, 2, 82, 10, 32, 2, 79, 2, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(36, 1140000, 1.65, 91, 4, 72, 2, 79, 9, 34, 4, 57, 2, 65, 1, 1148000, 2.4, 94, 4, 76, 2, 52, 3, 65));
                //warianty.List.Add(new EWariant(37, 471000, 1.4, 95, 3, 29, 1, 66, 9, 81, 2, 86, 1, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(38, 476000, 4.9, 25, 2, 67, 1, 73, 2, 32, 1, 98, 2, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(39, 411000, 2.06, 90, 3, 63, 1, 69, 9, 41, 3, 61, 3, 87, 1, 663000, 1.4, 55, 3, 50, 1, 69, 3, 67));
                //warianty.List.Add(new EWariant(40, 332000, 1.9, 37, 2, 32, 1, 20, 10, 29, 2, 67, 0, 52, 1, 342000, 1.9, 44, 2, 62, 1, 50, 1, 41));

                //warianty.List.Add(new EWariant(41, 612000, 2.06, 78, 3, 100, 1, 51, 10, 67, 3, 27, 1, 96, 1, 58800, 1.4, 76, 3, 48, 1, 96, 2, 38));
                //warianty.List.Add(new EWariant(42, 720000, 1.06, 61, 3, 43, 1, 50, 10, 57, 2, 29, 1, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(43, 424000, 0.9, 20, 2, 22, 2, 36, 5, 84, 2, 37, 1, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(44, 684000, 3.06, 75, 3, 58, 1, 72, 6, 97, 3, 41, 1, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(45, 452000, 5.4, 47, 2, 87, 1, 34, 6, 48, 2, 83, 2, 42, 1, 302000, 4.9, 62, 2, 99, 1, 52, 0, 71));
                //warianty.List.Add(new EWariant(46, 417000, 1.4, 53, 3, 73, 3, 58, 3, 74, 2, 39, 1, 98, 1, 495000, 3.06, 39, 3, 24, 3, 74, 2, 62));
                //warianty.List.Add(new EWariant(47, 1518000, 0.73, 74, 6, 87, 1, 76, 7, 48, 5, 71, 5, 97, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(48, 735000, 1, 72, 5, 95, 3, 61, 6, 68, 4, 52, 5, 91, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(49, 630000, 1.06, 97, 3, 74, 2, 87, 9, 79, 3, 65, 2, 67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(50, 453000, 2.4, 81, 3, 100, 3, 98, 10, 59, 2, 90, 3, 24, 1, 351000, 0.7, 33, 3, 67, 3, 28, 3, 61));

                //warianty.List.Add(new EWariant(51, 861000, 3.4, 34, 3, 68, 2, 30, 10, 47, 3, 42, 3, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(52, 314000, 4.4, 19, 2, 34, 2, 91, 9, 42, 1, 57, 0, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(53, 615000, 1.06, 30, 3, 82, 2, 29, 7, 60, 3, 94, 2, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(54, 1490000, 0.6, 55, 5, 84, 4, 93, 6, 90, 5, 66, 3, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(55, 1326000, 1.06, 99, 6, 77, 1, 100, 6, 88, 5, 79, 5, 88, 1, 936000, 1.4, 82, 6, 63, 1, 97, 6, 48));
                //warianty.List.Add(new EWariant(56, 908000, 1.65, 47, 4, 76, 1, 37, 8, 82, 3, 95, 2, 46, 1, 1100000, 1.4, 72, 4, 95, 1, 74, 4, 84));
                //warianty.List.Add(new EWariant(57, 840000, 2.15, 43, 4, 91, 3, 48, 8, 44, 4, 77, 3, 81, 1, 1164000, 0.65, 56, 4, 39, 3, 65, 2, 83));
                //warianty.List.Add(new EWariant(58, 1016000, 1.65, 94, 4, 85, 1, 56, 4, 33, 4, 82, 2, 92, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(59, 456000, 0.9, 55, 4, 38, 1, 62, 9, 57, 4, 89, 2, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(60, 1692000, 1.9, 97, 6, 58, 3, 91, 6, 90, 6, 70, 5, 89, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));

                //warianty.List.Add(new EWariant(61, 1547000, 0.82, 60, 7, 68, 5, 63, 7, 82, 7, 65, 7, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
                //warianty.List.Add(new EWariant(62, 952000, 0.54, 58, 7, 81, 4, 78, 7, 68, 6, 83, 7, 61, 1, 1008000, 0.68, 62, 7, 72, 4, 76, 7, 66));
                //warianty.List.Add(new EWariant(63, 672000, 1.23, 89, 6, 100, 1, 63, 7, 55, 5, 85, 4, 60, 1, 175200, 0.73, 52, 6, 89, 1, 60, 4, 64));

                //Console.WriteLine("K1 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 1).Value), warianty.List.Max(w => w.K.First(k => k.Id == 1).Value));
                //Console.WriteLine("K2 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 2).Value), warianty.List.Max(w => w.K.First(k => k.Id == 2).Value));
                //Console.WriteLine("K3 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 3).Value), warianty.List.Max(w => w.K.First(k => k.Id == 3).Value));
                //Console.WriteLine("K4 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 4).Value), warianty.List.Max(w => w.K.First(k => k.Id == 4).Value));
                //Console.WriteLine("K5 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 5).Value), warianty.List.Max(w => w.K.First(k => k.Id == 5).Value));
                //Console.WriteLine("K6 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 6).Value), warianty.List.Max(w => w.K.First(k => k.Id == 6).Value));
                //Console.WriteLine("K7 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 7).Value), warianty.List.Max(w => w.K.First(k => k.Id == 7).Value));
                //Console.WriteLine("K8 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 8).Value), warianty.List.Max(w => w.K.First(k => k.Id == 8).Value));
                //Console.WriteLine("K9 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 9).Value), warianty.List.Max(w => w.K.First(k => k.Id == 9).Value));
                //Console.WriteLine("K10 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 10).Value), warianty.List.Max(w => w.K.First(k => k.Id == 10).Value));
                //Console.WriteLine("K11 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 11).Value), warianty.List.Max(w => w.K.First(k => k.Id == 11).Value));
                //Console.WriteLine("K12 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 12).Value), warianty.List.Max(w => w.K.First(k => k.Id == 12).Value));
                //Console.WriteLine("K13 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 13).Value), warianty.List.Max(w => w.K.First(k => k.Id == 13).Value));
                //Console.WriteLine("K14 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 14).Value), warianty.List.Max(w => w.K.First(k => k.Id == 14).Value));
                //Console.WriteLine("K15 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 15).Value), warianty.List.Max(w => w.K.First(k => k.Id == 15).Value));
                //Console.WriteLine("K16 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 16).Value), warianty.List.Max(w => w.K.First(k => k.Id == 16).Value));
                //Console.WriteLine("K17 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 17).Value), warianty.List.Max(w => w.K.First(k => k.Id == 17).Value));
                //Console.WriteLine("K18 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 18).Value), warianty.List.Max(w => w.K.First(k => k.Id == 18).Value));
                //Console.WriteLine("K19 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 19).Value), warianty.List.Max(w => w.K.First(k => k.Id == 19).Value));
                //Console.WriteLine("K20 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 20).Value), warianty.List.Max(w => w.K.First(k => k.Id == 20).Value));
                //Console.WriteLine("K21 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 21).Value), warianty.List.Max(w => w.K.First(k => k.Id == 21).Value));
                //Console.WriteLine("K22 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 22).Value), warianty.List.Max(w => w.K.First(k => k.Id == 22).Value));
                //Console.WriteLine("K23 min {0}, max {1}", warianty.List.Min(w => w.K.First(k => k.Id == 23).Value), warianty.List.Max(w => w.K.First(k => k.Id == 23).Value));

                //Console.ReadLine();

                serializer.Serialize(wstream, warianty);
            }
        }
        private static void GenerateWariantyTestowe()
        {
            var serializer = new XmlSerializer(typeof(EWariantyList));
            using (TextWriter wstream =
                new StreamWriter(
                    "warianty.txt"))
            {
                var warianty = new EWariantyList();

                warianty.List.Add(new EWariant(1, "W1", 1, 2, 3));
                warianty.List.Add(new EWariant(2, "W2", 2, 3, 1));
                warianty.List.Add(new EWariant(3, "W3", 3, 2, 1));
                warianty.List.Add(new EWariant(4, "W4", 2, 3, 4));
                warianty.List.Add(new EWariant(5, "W5", 3, 1, 1));
                warianty.List.Add(new EWariant(6, "W6", 4, 5, 1));
                warianty.List.Add(new EWariant(7, "W7", 3, 1, 6));

                serializer.Serialize(wstream, warianty);
            }
        }
        private static void GenerateProfile()
        {
            var serializer = new XmlSerializer(typeof(EWariantyList));
            using (TextWriter wstream =
                new StreamWriter(
                    "profile.txt"))
            {
                var profile = new EWariantyList();

                profile.List.Add(new EWariant(1, "P_dolny", 200000, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0));
                profile.List.Add(new EWariant(2, "P_0.25", 600000, 4.7, 33, 3.5, 38, 3, 38, 4, 45, 2.5, 38, 3, 45, 0.25, 600000, 4.5, 25, 2.5, 35, 1.8, 35, 1.8, 32));
                profile.List.Add(new EWariant(3, "P_0.5", 1000000, 3.2, 55, 5, 50, 5, 55, 6, 60, 4, 60, 5, 60, 0.5, 1000000, 3, 50, 5, 50, 3, 50, 3.5, 50));
                profile.List.Add(new EWariant(4, "P_0.75", 1400000, 1.2, 78, 7.5, 78, 7.5, 78, 8, 80, 8, 80, 8, 80, 1.1, 1500000, 1, 75, 7.5, 75, 4.1, 75, 5.5, 75));
                profile.List.Add(new EWariant(5, "P_gorny", 2000000, 0, 100, 10, 100, 10, 100, 10, 100, 10, 100, 10, 100, 2, 2000000, 0, 100, 10, 100, 10, 100, 10, 100));

                serializer.Serialize(wstream, profile);
            }
        }
        private static void GenerateProfileTestowe()
        {
            var serializer = new XmlSerializer(typeof(EWariantyList));
            using (TextWriter wstream =
                new StreamWriter(
                    "profile.txt"))
            {
                var profile = new EWariantyList();

                profile.List.Add(new EWariant(1, "P1", 0, 0, 0));
                profile.List.Add(new EWariant(2, "P2", 1, 3, 4));
                profile.List.Add(new EWariant(3, "P3", 3, 4, 3));
                profile.List.Add(new EWariant(4, "P4", 2, 3, 4));
                profile.List.Add(new EWariant(5, "P5", 3, 7, 7));
                profile.List.Add(new EWariant(6, "P6", 6, 8, 9));
                profile.List.Add(new EWariant(7, "P7", 10, 10, 10));

                serializer.Serialize(wstream, profile);
            }
        }
        private static void GenerateKryteria()
        {
            var serializer = new XmlSerializer(typeof(EKryteriaList));
            using (TextWriter wstream =
                new StreamWriter(
                    "kryteria.txt"))
            {
                var kryteria = new EKryteriaList();

                kryteria.List.Add(new EKryterium(1, 6, 30000, 55000, 0, "K1", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(2, 2, 0.1, 0.3, 0, "K2", EKryteriumTyp.Koszt));
                kryteria.List.Add(new EKryterium(3, 4, 8, 15, 0, "K3", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(4, 5, 1, 3, 0, "K4", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(5, 3, 5, 15, 0, "K5", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(6, 6, 1, 3, 0, "K6", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(7, 3, 5, 15, 0, "K7", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(8, 3, 1, 3, 0, "K8", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(9, 1, 5, 15, 0, "K9", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(10, 1, 1, 3, 0, "K10", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(11, 1, 5, 15, 0, "K11", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(12, 3, 1, 3, 0, "K12", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(13, 1, 5, 15, 0, "K13", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(14, 1, 0, 0, 0, "K14", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(15, 1, 20000, 50000, 0, "K15", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(16, 1, 0.1, 0.3, 0, "K16", EKryteriumTyp.Koszt));
                kryteria.List.Add(new EKryterium(17, 1, 5, 15, 0, "K17", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(18, 1, 2, 4, 0, "K18", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(19, 1, 5, 15, 0, "K19", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(20, 1, 1, 4, 0, "K20", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(21, 1, 5, 15, 0, "K21", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(22, 1, 3, 5, 0, "K22", EKryteriumTyp.Zysk));
                kryteria.List.Add(new EKryterium(23, 1, 5, 15, 0, "K23", EKryteriumTyp.Zysk));


                serializer.Serialize(wstream, kryteria);
            }
        }
        private static void GenerateKryteriaTestowe()
        {
            var serializer = new XmlSerializer(typeof(EKryteriaList));
            using (TextWriter wstream =
                new StreamWriter(
                    "kryteria.txt"))
            {
                var kryteria = new EKryteriaList();

                kryteria.List.Add(new EKryterium(1, 0.7, 0.3, 0.8, -1, "K1", EKryteriumTyp.Koszt));
                kryteria.List.Add(new EKryterium(2, 0.6, 0.3, 0.8, 0.5, "K2", EKryteriumTyp.Koszt));
                kryteria.List.Add(new EKryterium(3, 0.9, 0.3, 0.8, 1, "K3", EKryteriumTyp.Zysk));

                serializer.Serialize(wstream, kryteria);
            }
        }

        #endregion
    }
}
